package rok3.zesp.projekt.models;

import rok3.zesp.projekt.Resources;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable;

public class ColdDownBar {
	Image img;
	float cd;
	float timer;
	float baseWidth;
	
	public ColdDownBar () {
		
	}
	
	public Image getImage () {
		if ( img == null ) {
			img = new Image (new TiledDrawable(Resources.TextureType.getColdDownBarFillDrawable())){
				@Override
				public void draw(SpriteBatch batch, float parentAlpha) {
					if (ColdDownBar.this.isInColdDown() )
						this.setWidth(ColdDownBar.this.baseWidth*(ColdDownBar.this.timer/ColdDownBar.this.cd));
					super.draw(batch, parentAlpha);
				}
			};
		}
		return img;
	}

	public boolean isInColdDown() {
		return timer>0;
	}
	
	public void startColdDown() {
		timer = cd;
	}

	public void update(float delta) {
		timer = timer > 0 ? timer - delta: 0;
	}
}
